/*
 * @Author: 欧小兵
 * @Date: 2022-01-14 15:05:34
 * @LastEditors: 欧小兵
 * @LastEditTime: 2022-01-18 18:37:26
 * @FilePath: \pc-collaboration\src\handles\handle-list\modules\add-info-node.js
 * @Description:
 */
import { useBaseInfoWithOut } from '@/store/modules/base-info';
const useBaseInfo = useBaseInfoWithOut();

import { WORKFLOW_OPERATION_TYPE } from '@/utils/const.js';

//知会
function addInfoNode(item, resolve) {
    console.log('add info node');
    // var informNodeParams = JSON.parse('{"workitemId":"-2752494093598310314","processId":"685180136891040237","nodeId":"8819763136253152926","caseId":"-5915982984914713795","appName":"collaboration","isForm":true,"affairId":"3433114185491039752","useNowexpirationTime":"true","NPS":"form","SPK":"informNode","performer":"-1042970111192971164","summaryId":"-4321114601722724140","formRecordId":"-6714557521657181322","defaultPolicyId":"collaboration","accountId":"155524161881130422","flowPermAccountId":"155524161881130422","accessFileSecretLevel":null}');
    const informNodeParams = getAddInfoNodeParams(WORKFLOW_OPERATION_TYPE.INFORM_NODE);

    informNodeParams.isNeedCheckLevelScope = true;
    informNode(informNodeParams);
}

//获取知会参数
function getAddInfoNodeParams(type) {
    console.log(['type', WORKFLOW_OPERATION_TYPE[type]]);
    let result = {
        NPS: 'form',
        SPK: WORKFLOW_OPERATION_TYPE[type],
        accessFileSecretLevel: null,
        accountId: '155524161881130422',
        affairId: '3433114185491039752',
        appName: 'collaboration',
        caseId: '-5915982984914713795',
        defaultPolicyId: 'collaboration',
        flowPermAccountId: '155524161881130422',
        formRecordId: '-6714557521657181322',
        isForm: true,
        nodeId: '8819763136253152926',
        performer: '-1042970111192971164',
        processId: '685180136891040237',
        summaryId: '-4321114601722724140',
        useNowexpirationTime: 'true',
        workitemId: '-2752494093598310314',
    };

    return result;
}

function _operation_getChangeWorkflowParamFn(type) {
    // 指定回退状态
    var isForm = bodyType == '20';

    var changeWorkflowParam = {
        workitemId: wfItemId,
        processId: wfProcessId,
        nodeId: wfActivityId,
        caseId: wfCaseId,
        appName: 'collaboration',
        isForm: isForm,
        callback: refreshWorkflow,
        affairId: affairId,
        useNowexpirationTime: 'true',
    };

    if (isForm) {
        changeWorkflowParam.NPS = 'form';
    } else {
        changeWorkflowParam.NPS = 'default';
    }

    var tempSPK = '';
    switch (type) {
        case 'AddNode':
            tempSPK = 'insertNode';
            break;
        case 'Infom':
            tempSPK = 'informNode';
            break;
        case 'JointSign':
            tempSPK = 'assignNode';
            break;
        case 'moreSign':
            tempSPK = 'nodeOperation4Account';
            if (adminType == 'formAdmin') {
                tempSPK = 'nodeOperation4Form';
            }
            break;
        default:
            break;
    }
    changeWorkflowParam.SPK = tempSPK;

    if (type == 'AddNode' || type == 'Infom' || type == 'JointSign') {
        changeWorkflowParam.performer = currUserId;
        changeWorkflowParam.summaryId = summaryId;
        changeWorkflowParam.formRecordId = formRecordid;
    } else {
        // 多级会签独有的参数
        changeWorkflowParam.affairMemberId = currUserId;
        changeWorkflowParam.workitemId = wfItemId;
        //changeWorkflowParam.formId = formId;
        //changeWorkflowParam.flowPermAccountId = _accountId;
        changeWorkflowParam.callBackFn = refreshWorkflow;
        changeWorkflowParam.selectPeopleDialogLeftTitle = '';
        changeWorkflowParam.panels = 'Department,Team,BusinessDepartment,Post';
    }

    if (type == 'Infom') {
        changeWorkflowParam.defaultPolicyId = 'collaboration';
    } else if (type == 'JointSign') {
        changeWorkflowParam.defaultPolicyId = nodePolicy;
        changeWorkflowParam.defaultPolicyName = nodePolicyName;
    }

    changeWorkflowParam.accountId = flowPermAccountId;
    changeWorkflowParam.flowPermAccountId = flowPermAccountId;

    if (type == 'AddNode' || type == 'moreSign') {
        changeWorkflowParam.isTemplete = isTemplete;
    }
    var secretLevelTemp = null;
    if (isSecretLevelEnable) {
        var secretObj = $('#secretLevel');
        if (typeof secretObj != 'undefined' && typeof secretObj.val != 'undefined') {
            secretLevelTemp = secretObj.val();
        }
        //密级为空可能是0 secretLevelTemp == "0"
        if (secretLevelTemp == '' || secretLevelTemp == '0') {
            secretLevelTemp = null;
        }
    }
    changeWorkflowParam.accessFileSecretLevel = secretLevelTemp;
    return changeWorkflowParam;
}

export default (item) =>
    new Promise((resolve) => {
        addInfoNode(item, resolve);
    });
